package remote.controls
{
	import flash.events.MouseEvent;
	
	import remote.collections.SelectGroup;
	
	
	/**
	 * 可选对象组，对于组中的Button，可以选中一个或多个。
	 * 点击组中的按钮时，点击的按钮会自动被选中。
	 * maxSelectedCount决定了最大选中数量，选中对象的数量超过此值时，早期被选中的对象被取消选中
	 * 
	 * @author 银魂飞雪
	 * @createDate 2011-4-2
	 */
	public class ButtonGroup extends SelectGroup
	{
		public function ButtonGroup()
		{
			super();
		}
		/**
		 * @inheritDoc 
		 * 
		 */		
		override public function addItem(item:Object):void
		{
			super.addItem(item);
			(item as Button).addEventListener(MouseEvent.CLICK, item_clickHandler);
		}
		/**
		 * @inheritDoc 
		 * 
		 */	
		override public function addItemAt(item:Object, index:int):void
		{
			super.addItemAt(item, index);
			(item as Button).addEventListener(MouseEvent.CLICK, item_clickHandler);
		}
		/**
		 * @inheritDoc 
		 * 
		 */	
		override public function removeItem(item:Object):Object
		{
			super.removeItem(item);
			(item as Button).removeEventListener(MouseEvent.CLICK, item_clickHandler);
			return item;
		}
		/**
		 * @inheritDoc 
		 * 
		 */	
		override public function removeItemAt(index:int):Object
		{
			super.removeItemAt(index);
			(getItemAt(index) as Button).removeEventListener(MouseEvent.CLICK, item_clickHandler);
			return getItemAt(index);
		}
		/**
		 * @inheritDoc 
		 * 
		 */	
		protected function item_clickHandler(e:MouseEvent):void
		{
			this.selectItem(e.currentTarget as Button);	
		}
	}
}